본 게시글의 원문은 Yann Debray의 MATLAB with Python Book 입니다. 해당 책은 MIT 라이센스를 따르기 때문에 개인적으로 번역하여 재배포 합니다. 본 포스팅에는 추후 유료 수익을 위한 광고가 부착될 수도 있습니다.

MIT License

Copyright (c) 2023 Yann Debray

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.

본 게시물에서 활용된 소스 코드들은 모두 Yann Debray의 GitHub Repo에서 확인할 수 있습니다.

3.5. Python 가상 환경 설정하기

만약 서로 다른 프로젝트가 동일한 패키지의 다른 버전을 사용하거나 생산 환경을 깨끗한 공간에서 재현하고 싶다면 Python 가상 환경을 사용하세요. 이것은 언어 수준에서의 가상화 방법입니다 (기계 수준에서의 가상 머신이나 운영 체제 수준의 Docker 컨테이너와 비슷한 역할을 합니다). 다음은 env라는 이름의 가상 환경을 만드는 기본 방법입니다:

C:\Users\ydebray>python -m venv env

그런 다음 아래와 같이 활성화해야 합니다.

  • Windows에서:
C:\Users\ydebray>.\env\Scripts\activate
  • Linux에서:
$ source env/bin/activate

이렇게 하면 원하는 라이브러리를 설치할 수 있습니다. 예를 들어 요구 사항 목록에서 설치하려면:

C:\Users\ydebray>pip install -r requirements.txt